// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import VueResource from 'vue-resource'
import utils from './utils'

Vue.config.productionTip = false
Vue.use(VueResource)
Vue.prototype.utils = utils

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: {App},
  template: '<App/>',
  created () {
    if (this.utils.getUser() != null) {
        var url = window.location.href.substr(0, window.location.href.indexOf("#"))
        if(this.utils.getRequestData().path!=null){
            window.location.href = (url+this.utils.getRequestData().path)
        }
      Vue.http.interceptors.push(function (request, next) {
        if (request.url.indexOf('http') > -1) {
          next(function (response) {
            return response
          })
        } else {
          request.headers.set('userId', this.utils.getUser().userId)
          request.url = this.utils.$config.server.prefix + this.utils.$config.server.host + ':' + this.utils.$config.server.port + '/' + request.url
          next(function (response) {
            if (response.body.errorCode !== 10001 && response.body.flag === 0) {
             // alert(response.body.msg)
            } else {
              return response
            }
          })
        }
      })
    }
  }
})
